package test.service;

import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 比较器test
 *
 * @author bingo
 * @create 2017-12-06 10:36
 **/
public class PersonDemo implements Comparable<PersonDemo> {

    private Logger logger  = LoggerFactory.getLogger(PersonDemo.class);

    private String username;

    private Integer age;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public PersonDemo(String username, Integer age) {
        this.username = username;
        this.age = age;
    }

    @Override
    public int compareTo(PersonDemo o) {
logger.info("this.age={},to.age={}",this.age,o.getAge());
        return this.getAge()-o.getAge();
    }

    @Override
    public String toString() {
        return "PersonDemo{" +
                "username='" + username + '\'' +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) {
        List list =  new ArrayList();
        list.add(new PersonDemo("aa",2));
        list.add(new PersonDemo("bb",3));
        list.add(new PersonDemo("cc",1));
        Collections.sort(list);
        System.out.println(list.toString());

    }
}
